<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
  var findContentChildren = function(g, s) {
    g = g.sort((a, b) => a - b)
    s = s.sort((a, b) => a - b)
    console.log(g)
    console.log(s)
    let result = 0
    let index = s.length - 1
    for(let i = g.length - 1; i >= 0; i--) {
      if(index >= 0 && s[index] >= g[i]) {
        result++
        index--
      }
    }
    return result
  };
  var person = [1,4,6,7]
  var cookie = [5,6,1,10]
  var res = findContentChildren(person, cookie)
  console.log(res)
</script>
</body>
</html>